{% extends "base.html" %}

{% block title %}角色权限分配 - 网站管理后台{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">角色权限分配</h1>
</div>

<div class="row">
    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-header">
                <h5>角色信息</h5>
            </div>
            <div class="card-body">
                <p><strong>角色名称:</strong> {{ role[1] }}</p>
                <p><strong>描述:</strong> {{ role[2] if role[2] else '-' }}</p>
                <p><strong>状态:</strong> 
                    {% if role[3] == 1 %}
                        <span class="badge bg-success">启用</span>
                    {% else %}
                        <span class="badge bg-secondary">禁用</span>
                    {% endif %}
                </p>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <form method="POST">
            <div class="card">
                <div class="card-header">
                    <h5>分配权限</h5>
                </div>
                <div class="card-body">
                    <div class="form-check">
                        {% for permission in all_permissions %}
                        <div class="mb-2">
                            <input class="form-check-input" type="checkbox" name="permissions" value="{{ permission[0] }}" 
                                   id="permission_{{ permission[0] }}" {% if permission[0] in role_permission_ids %}checked{% endif %}>
                            <label class="form-check-label" for="permission_{{ permission[0] }}">
                                {{ permission[1] }} ({{ permission[2] }})
                                {% if permission[4] %}
                                    <small class="text-muted"> - {{ permission[4] }}</small>
                                {% endif %}
                            </label>
                        </div>
                        {% endfor %}
                    </div>
                </div>
                <div class="card-footer">
                    <button type="submit" class="btn btn-primary">保存权限分配</button>
                    <a href="{{ url_for('web.roles') }}" class="btn btn-secondary">返回角色列表</a>
                </div>
            </div>
        </form>
    </div>
</div>
{% endblock %}